package com.ruix.app.model;

import com.ruix.app.ui.message.MessagePostActivity;
import com.ruix.app.ui.message.MessageReportActivity;

import org.json.JSONObject;

import java.io.Serializable;

/**
 * Created by hadexs on 2017/5/7.
 */

public class MessageModel implements Serializable{

    private String ID;
    private String content;
    private String originContent;
    private String oid;
    private String fromId;
    private String fromName;
    private String fromAvatar;
    private String fromCid;
    private String fromCname;
    private String type;
    private long createdTime;
    private boolean read;


    public MessageModel parse(JSONObject object){
        if (object != null){
            setID(object.optString("id",""));
            setContent(object.optString("content",""));
            setOriginContent(object.optString("origin_content",""));
            setOid(object.optString("oid",""));
            setFromId(object.optString("from_id",""));
            setFromName(object.optString("from_name",""));
            setFromAvatar(object.optString("from_avatar",""));
            setFromCid(object.optString("from_cid",""));
            setFromCname(object.optString("from_cname",""));
            setType(object.optString("type",""));
            setCreatedTime(object.optLong("created_at",0) * 1000);
            setRead(object.optInt("read",0) == 1);

        }
        return this;
    }

    public String getID() {
        return ID;
    }

    public void setID(String ID) {
        this.ID = ID;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getOriginContent() {
        return originContent;
    }

    public void setOriginContent(String originContent) {
        this.originContent = originContent;
    }

    public String getOid() {
        return oid;
    }

    public void setOid(String oid) {
        this.oid = oid;
    }

    public String getFromId() {
        return fromId;
    }

    public void setFromId(String fromId) {
        this.fromId = fromId;
    }

    public String getFromName() {
        return fromName;
    }

    public void setFromName(String fromName) {
        this.fromName = fromName;
    }

    public String getFromAvatar() {
        return fromAvatar;
    }

    public void setFromAvatar(String fromAvatar) {
        this.fromAvatar = fromAvatar;
    }

    public String getFromCid() {
        return fromCid;
    }

    public void setFromCid(String fromCid) {
        this.fromCid = fromCid;
    }

    public String getFromCname() {
        if (fromCname != null){
            return fromCname.trim();
        }
        return fromCname;
    }

    public void setFromCname(String fromCname) {
        this.fromCname = fromCname;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public long getCreatedTime() {
        return createdTime;
    }

    public void setCreatedTime(long createdTime) {
        this.createdTime = createdTime;
    }

    public boolean isRead() {
        return read;
    }

    public void setRead(boolean read) {
        this.read = read;
    }

    public String getMessageTitle(){
        if ("1".equals(type)) {
            return String.format("%s 赞你的实践：%s",fromName,content);
        } else if ("2".equals(type)) {
            return String.format("%s 打赏了您：%s",fromName,content);
        } else if ("3".equals(type)) {
            return String.format("通知：%s",content);
        } else if ("4".equals(type)) {
         return String.format("%s 评论了你的实践：%s",fromName,content);
        } else if ("5".equals(type)) {
            return "您的举报已处理";
        }else if ("6".equals(type)) {
            return "您的举报已处理";
        }
        return "";

    }
}
